//
// Created by kongkong on 2016/11/1.
// Copyright (c) 2016 Kongkong. All rights reserved.
//

#import <Foundation/Foundation.h>

typedef enum eServerReturnCode {
    RET_NORMAL = 200,
    RET_ILLEGAL = 400,
    RET_SERVER_ERROR = 500,
    RET_CLIENT_ERROR = 0,
} ServerReturnCode;

/**
 {
 ret:    xxx
 msg:    xxx
 data:{
 code:   xxx
 msg:    xxx
 result: {
 }
 }
 }
 **/


@protocol KKResponseProtocol <NSObject>

/** origin response *****************************/
@property (nonatomic,strong,readonly) NSDictionary* originalData;

@property (nonatomic,assign,readonly) ServerReturnCode ret;
@property (nonatomic,strong,readonly) NSString* serverMessage;

@property (nonatomic,assign,readonly) int bizCode;
@property (nonatomic,strong,readonly) NSString* bizMsg;

@property (nonatomic,strong,readonly) id originResult;
/*******************************/

/** 解析 数据 *****************************/
@property (nonatomic,strong,readonly) id result;

@property (nonatomic,strong) NSError *error;

/**
 * 请求是否成功
 **/
- (BOOL)isSuccess;

/**
 * 错误信息
 * @return
 */
- (NSString *)errorMessage;

+ (id<KKResponseProtocol>)objectWithData:(NSDictionary *)data reflexClass:(Class)reflexClass;

- (void)showError;
@end
